package com.user.domain.vo;

import com.common.enums.user.*;
import com.common.util.EncryptionUtil;
import com.common.util.GrepUtil;
import com.core.domain.CoreVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * @author: stefanie-zy
 * @time: 2024/1/25-16:24
 * @description: Vo-用户
 */
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Data
@Schema(name = "Vo-用户")
public class UserVo extends CoreVo implements Serializable {
    @Serial
    private static final long serialVersionUID = -4314608182262236025L;

    @Schema(description = "姓名")
    private String userName;

    @Schema(description = "昵称")
    private String nickName;

    @Schema(description = "登录名")
    private String loginName;

    @Schema(description = "微信名称")
    private String wechat;

    @Schema(description = "密码等级")
    private PasswordLevelEnum passwordLevel;

    @Schema(description = "密码错误次数")
    private Integer wrPasswordNum;

    @Schema(description = "类型")
    private UserTypeEnum type;

    @Schema(description = "手机号")
    private String phoneNumber;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "性别")
    private SexEnum sex;

    @Schema(description = "身份证")
    private String idCard;

    @Schema(description = "地址")
    private String address;

    @Schema(description = "头像")
    private String icoUrl;

    @Schema(description = "用户状态")
    private UserStatusEnum status;

    @Schema(description = "登录状态")
    private LoginStatusEnum loginStatus;

    @Schema(description = "登录ip")
    private String loginIp;

    @Schema(description = "登录时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date loginTime;


    // 脱敏数据
    @Schema(description = "脱敏：手机号")
    private String phoneNumberVague;
    @Schema(description = "脱敏：身份证")
    private String idCardVague;
    @Schema(description = "脱敏：地址")
    private String addressVague;
    @Schema(description = "脱敏：邮箱")
    private String emailVague;

    // 脱敏处理
    public String getPhoneNumber() {
        // 解密处理
        return EncryptionUtil.decode(this.phoneNumber);
    }

    public String getIdCard() {
        // 解密处理
        return EncryptionUtil.decode(this.idCard);
    }

    public String getAddress() {
        // 解密处理
        return EncryptionUtil.decode(this.address);
    }

    public String getEmail() {
        // 解密处理
        return EncryptionUtil.decode(this.email);
    }

    public String getPhoneNumberVague() {
        // 脱敏处理
        return GrepUtil.phoneNumberHide(getPhoneNumber());
    }

    public String getIdCardVague() {
        // 脱敏处理
        return GrepUtil.idCardHide(getIdCard());
    }

    public String getAddressVague() {
        // 脱敏处理
        return GrepUtil.addressHide(getAddress());
    }

    public String getEmailVague() {
        // 脱敏处理
        return GrepUtil.emailHide(getEmail());
    }
}
